package com.zbbt.sportslottery.ui.adapter;

import java.util.List;

import android.R.integer;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zbbt.sportslottery.R;
import com.zbbt.sportslottery.bean.DianZhuHuoDongQuanData;
import com.zbbt.sportslottery.util.TimeUtil;

public class DZHDQListAdapter extends BaseAdapter {
	private OnBottomClickListener clickLonbottomistener;
	private LayoutInflater mInflater;
	private List<DianZhuHuoDongQuanData> dataList;
	private Context context;

	public DZHDQListAdapter(Context context, List<DianZhuHuoDongQuanData> dataList) {
		mInflater = LayoutInflater.from(context);
		this.dataList = dataList;
		this.context=context;
	}

	public int getCount() {
		return dataList.size();
	}

	public Object getItem(int position) {
		return dataList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_dianzhu_huodong, null);
			holder = new ViewHolder();
			holder.huodongquan_name_tx = (TextView) convertView.findViewById(R.id.huodongquan_name_tx);
			holder.value_tx = (TextView) convertView.findViewById(R.id.value_tx);
			holder.redeem_time_tx = (TextView) convertView.findViewById(R.id.redeem_time_tx);
			holder.tvDollar=(TextView) convertView.findViewById(R.id.dollar);
			holder.tvYuan=(TextView) convertView.findViewById(R.id.yuan_tx);
			holder.huodongquanContent=(LinearLayout) convertView.findViewById(R.id.huodongquan_content);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		DianZhuHuoDongQuanData mBean = dataList.get(position);
		holder.value_tx.setText(mBean.getPrice()+"");
		holder.huodongquan_name_tx.setText(mBean.getCouponName());
		holder.redeem_time_tx.setText("兑换时间"+TimeUtil.getTimeDate(mBean.getRedeemTime()));
		if (mBean.getStatus() == 1) {// 未结算
			holder.huodongquanContent.setBackgroundResource(R.drawable.huodongquan_pic);
			holder.redeem_time_tx.setBackgroundResource(R.drawable.exchange_time_blue);
			holder.redeem_time_tx.setPadding(25, 0, 25, 0);
			holder.redeem_time_tx.setTextColor(context.getResources().getColor(R.color.blue));
			holder.tvDollar.setTextColor(context.getResources().getColor(R.color.red));
			holder.tvYuan.setTextColor(context.getResources().getColor(R.color.red));
			holder.value_tx.setTextColor(context.getResources().getColor(R.color.red));
		} else if (mBean.getStatus() == 2) {// 已结算
			holder.huodongquanContent.setBackgroundResource(R.drawable.huodongquan_isuse_bg);
			holder.redeem_time_tx.setBackgroundResource(R.drawable.exchange_time_grey);
			holder.redeem_time_tx.setPadding(25, 0, 25, 0);
			holder.redeem_time_tx.setTextColor(context.getResources().getColor(R.color.gray_tq));
			holder.tvDollar.setTextColor(context.getResources().getColor(R.color.gray_tq));
			holder.tvYuan.setTextColor(context.getResources().getColor(R.color.gray_tq));
			holder.value_tx.setTextColor(context.getResources().getColor(R.color.gray_tq));
		}
		if (position == dataList.size() - 1) {
			if (clickLonbottomistener != null) {
				clickLonbottomistener.onBottomClick();
			}
		}
		return convertView;
	}

	static class ViewHolder {
		public TextView huodongquan_name_tx;
		public TextView value_tx;
		public TextView redeem_time_tx;
		public TextView tvDollar;
		public TextView tvYuan;
		public LinearLayout huodongquanContent;
		
		
	}

	public interface OnBottomClickListener {
		public void onBottomClick();
	}

	public void setOnBottomClickListener(OnBottomClickListener clickListener) {
		this.clickLonbottomistener = clickListener;
	}
}
